$(function () {

    // 登录
    $(".login_btn").on("click", function () {
        console.log(111)
        var params = {
            utel: $('[name="utel"]').val(),
            upwd: $('[name="upwd"]').val()
        }
        console.log(params);
        $.ajax({
            url: "./api/login",
            data: params,
            type: "post"
        }).then(function (res) {
            console.log(res);
            if (res.status == 1) {
                $('[name="utel"]').val("");
                $('[name="upwd"]').val("");
                layer.alert("登录成功！", {
                    icon: 6
                }, function () {
                    window.location.href = window.location.href;
                });
                //cookie
                $.cookie("uname", JSON.stringify(res.data), { expirse: 10 });

                //localStorage
                // localStorage.setItem("loginInfo",JSON.stringify(res.data));
            } else {
                layer.alert("用户不存在或是密码错误！", { 
                    icon: 2
                });
                $('[name="upwd"]').val("");
                return;
            }
            $('[name="utel"]').val("");
            $('[name="upwd"]').val("");
        })
    })

    // 注册
    $(".reg_btn").on("click", function () {
        var params = {
            utel: $('[name="regutel"]').val(),
            upwd: $('[name="regupwd"]').val()
        }
        console.log(params)
        var str = "utel=" + params.utel + "&upwd=" + params.upwd;
        console.log(str);
        $.ajax({
            url: "./api/reg",
            data: params,
            type: "post",
        }).then(function (res) {
            console.log(res);
            if (res.status == 1) {
                layer.alert("注册成功！", {
                    icon: 6
                });
            } else {
                layer.alert("注册失败！", {
                    icon: 5
                });
            }
        })
    })


})